package com.weaver.openapi.service;

import com.weaver.openapi.pojo.message.params.*;
import com.weaver.openapi.pojo.*;
import com.weaver.openapi.util.*;
import java.util.*;
import cn.hutool.http.*;
import com.alibaba.fastjson.*;

public class MessageService
{
    public static ApiResult<String> sendMsg(final MessageVo messageVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/json");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", messageVo.getAccessToken());
        paramMap.put("text", messageVo.getText());
        paramMap.put("title", messageVo.getTitle());
        paramMap.put("sender", messageVo.getSender());
        paramMap.put("eventId", messageVo.getEventId());
        paramMap.put("moduleId", messageVo.getModuleId());
        paramMap.put("recivers", messageVo.getRecivers());
        paramMap.put("entity", messageVo.getEntity());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/api/mc/msg/sendMsg").body(JSONObject.toJSONString((Object)paramMap)).headerMap((Map)headers, true)).execute().body();
        return transferResult(resJson);
    }
    
    public static ApiResult<String> deleteMsg(final MessageVo messageVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/json");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", messageVo.getAccessToken());
        paramMap.put("operator", messageVo.getOperator());
        paramMap.put("msgId", messageVo.getMsgId());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/api/mc/msg/sendMsg").body(JSONObject.toJSONString((Object)paramMap)).headerMap((Map)headers, true)).execute().body();
        return transferResult(resJson);
    }
    
    public static ApiResult<String> markMsg(final MessageVo messageVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/json");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", messageVo.getAccessToken());
        paramMap.put("operator", messageVo.getOperator());
        paramMap.put("msgIds", messageVo.getMsgIds());
        paramMap.put("flag", messageVo.getFlag());
        paramMap.put("entityId", messageVo.getEntityId());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/api/mc/msg/markMsg").body(JSONObject.toJSONString((Object)paramMap)).headerMap((Map)headers, true)).execute().body();
        return transferResult(resJson);
    }
    
    public static ApiResult<String> transferResult(final String resJson) {
        final JSONObject jsonObject = JSONObject.parseObject(resJson);
        final String data = (String)jsonObject.getObject("data", (Class)String.class);
        final String code = (String)jsonObject.getObject("code", (Class)String.class);
        final String msg = (String)jsonObject.getObject("msg", (Class)String.class);
        final boolean status = (boolean)jsonObject.getObject("status", (Class)Boolean.class);
        final boolean fail = (boolean)jsonObject.getObject("fail", (Class)Boolean.class);
        final ApiResult<String> normalRes = new ApiResult<String>();
        normalRes.setData(data);
        normalRes.setCode(code);
        normalRes.setMsg(msg);
        normalRes.setStatus(status);
        normalRes.setFail(fail);
        return normalRes;
    }
}
